package chen.web.test;

import java.util.List;

import org.junit.Assert;

import chen.web.user.Role;
import chen.web.user.RoleManager;
import chen.web.user.RoleManagerImpl;
import junit.framework.TestCase;

public class RoleManagerTesting extends TestCase {

	RoleManager rm = new RoleManagerImpl();

	public void testCreateRole(){
		Role role = new Role();
		role.setName("fdsa");
		role.setDescription("fdsa");
		role.setLevel(3);
		rm.createRole(role); 
		Role newRole = rm.getRole(role.getId());
		Assert.assertEquals(role.getId(), newRole.getId());
		Assert.assertEquals(role.getName(), newRole.getName());
	}
	
	public void testGetAll(){
		int size = rm.getAllRoles().size();
		Assert.assertTrue(size > 0);
	}
	
	public void testModify(){
		List<Role> list = rm.getAllRoles();
		Role role = list.get(list.size()-1);
		String name = role.getName();
		role.setName("ssssss");
		rm.modify(role);
		Role newRole = rm.getRole(role.getId());
		Assert.assertNotSame(newRole.getName(), name);
		Assert.assertEquals("ssssss", newRole.getName());
	}
	
	public void testGet(){
		Role role = rm.getRole(1);
		Assert.assertNotNull(role);
	}
	
	public void testDelete(){
		List<Role> list = rm.getAllRoles();
		int size = list.size();
		Role role = list.get(0);
		rm.delete(role);
		int newSize = rm.getAllRoles().size();
		Assert.assertTrue(newSize == size-1);
	}
	
	
}
